package com.loong;

import com.loong.pojo.Robot;
import com.loong.pojo.RobotProperties;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@ConditionalOnClass(Robot.class)
@EnableConfigurationProperties(RobotProperties.class)
public class RobotAutoConfiguration {

    private final RobotProperties robotProperties;

    public RobotAutoConfiguration(RobotProperties robotProperties) {
        this.robotProperties = robotProperties;
    }

    @Bean
    @ConditionalOnProperty(name = "robot.enabled", havingValue = "true")
    public Robot robot() {
        Robot robot = new Robot();
        robot.setAccount(robotProperties.getAccount());
        robot.setPassword(robotProperties.getPassword());
        robot.setSecret(robotProperties.getSecret());
        return robot;
    }
}